﻿namespace TVersityDotNet.MediaLib
{
    using System;
    using System.Globalization;
    using System.Runtime.Serialization;
    using System.Xml.Linq;

    [DataContractAttribute]    
    public class MediaLibPeople : MediaLibResponseItem
    {
        [DataMember]
        public int ChildCount { get; set; }
        [DataMember]
        public bool Searchable { get; set; }
        [DataMember]
        public bool Restricted { get; set; }
        [DataMember]
        public string WriteStatus { get; set; }
        [DataMember]
        public Uri Icon { get; set; }
        [DataMember]
        public string ResString { get; set; }

        public MediaLibPeople(XElement xmlElement)
        {
            this.SearchClass = MediaLibClassType.People;
            this.RawXml = xmlElement;
            this.ProcessXmlElement();
        }

        public MediaLibPeople()
        {
            this.SearchClass = MediaLibClassType.NoClass;
            this.RawXml = null;            
        }

        public new void ProcessXmlElement()
        {            
            base.ProcessXmlElement();
            this.ChildCount = int.Parse(this.RawXml.Attribute("childCount").Value, CultureInfo.InvariantCulture);
            this.Searchable = bool.Parse(this.RawXml.Element(XName.Get("searchable", MediaLibResponseItem.Namespace_Base)).Value);
            this.Restricted = bool.Parse(this.RawXml.Attribute("restricted").Value);
            this.WriteStatus = this.RawXml.Element(XName.Get("writeStatus", MediaLibResponseItem.Namespace_Upnp)).Value;
            this.Icon = new Uri(this.RawXml.Element(XName.Get("icon", MediaLibResponseItem.Namespace_Upnp)).Value);
        }
    }

}
